#ifndef __POJDESERIALIZE_HEADER
#define __POJDESERIALIZE_HEADER

#include "poj_task.h"

// 仿函数，用于将消息队列内的字节流反序列为PojTask
struct PojDeserialize {
	static const int ITEM_COUNT = 5;
	PojTask operator() (const char *str) const {
		int max_buff_size = 10010;
		char *block = new char[max_buff_size];
		std::string s[ITEM_COUNT];		
		int index = 0, i, j;
		for (i = 0; i < ITEM_COUNT; i++) {
			if (i != ITEM_COUNT-1) {
				for (j = 0; str[index] != '|'; index++, j++) {
					block[j] = str[index];
				}
				index++, block[j] = '\0';
				s[i] = std::string(block);
			}
			else {
				strcpy(block, str+index);
			}
			s[i] = std::string(block);
		}

		delete[] block;
		return PojTask(s[0], s[1], s[2], s[3], s[4]); 
	}
};

#endif // __POJDESERIALIZE_HEADER
 

